<%@ page language="java" import="dao.*" pageEncoding="UTF-8" %>
 <%@ page language="java" import="java.util.*" %>
 <%@page import="util.*" %>
 <%@ include file="head.jsp" %>


<div style="padding: 10px" class="admin-content">
    <%
    String orderby = util.Request.get("order", "id"); // 获取搜索框中的排序字段、默认为发布时间
    String sort = util.Request.get("sort", "desc"); // 获取搜索框中的排序类型、默认为倒序
    
    String where = " 1=1 "; // 防止sql 搜索条件为： where and a=b 这样的错误
    
    // 以下是检测搜索框中是否填写了或者选择了什么，则写入sql 语句中
    
    if (request.getParameter("kechengxinxiid") != null && !"".equals(request.getParameter("kechengxinxiid"))) {
        where += " AND kechengxinxiid='" + request.getParameter("kechengxinxiid") + "' ";
    }
    if (request.getParameter("kechengbianhao") != null && !"".equals(request.getParameter("kechengbianhao"))) {
        where += " AND kechengbianhao LIKE '%" + request.getParameter("kechengbianhao") + "%'";
    }
    if (request.getParameter("kechengmingcheng") != null && !"".equals(request.getParameter("kechengmingcheng"))) {
        where += " AND kechengmingcheng LIKE '%" + request.getParameter("kechengmingcheng") + "%'";
    }
    if (request.getParameter("xuehao") != null && !"".equals(request.getParameter("xuehao"))) {
        where += " AND xuehao LIKE '%" + request.getParameter("xuehao") + "%'";
    }
    
    if (request.getParameter("xueqi") != null && !"".equals(request.getParameter("xueqi"))) {
        where += " AND xueqi ='" + request.getParameter("xueqi") + "'";
    }
    
    if (request.getParameter("banji") != null && !"".equals(request.getParameter("banji"))) {
        where += " AND banji ='" + request.getParameter("banji") + "'";
    }
    
    if (request.getParameter("xuehao") != null && !"".equals(request.getParameter("xuehao"))) {
        where += " AND xuehao LIKE '%" + request.getParameter("xuehao") + "%'";
    }
    if (request.getParameter("xueqi") != null && !"".equals(request.getParameter("xueqi"))) {
        where += " AND xueqi ='" + request.getParameter("xueqi") + "'";
    }
    if (request.getParameter("banji") != null && !"".equals(request.getParameter("banji"))) {
        where += " AND banji ='" + request.getParameter("banji") + "'";
    }
    if (request.getParameter("chengji_start") != null && !"".equals(request.getParameter("chengji_start"))) {
        where += " AND chengji >='" + request.getParameter("chengji_start") + "' ";
    }
    if (request.getParameter("chengji_end") != null && !"".equals(request.getParameter("chengji_end"))) {
        where += " AND chengji <='" + request.getParameter("chengji_end") + "' ";
    }
    List<Map> list = Query.make("xueshengchengji").where(where).order(orderby + " " + sort).page(15);
    
    Map total = Query
        .make("xueshengchengji")
        .field("(sum(chengji)) sum_chengji,(min(chengji)) min_chengji,(max(chengji)) max_chengji,(avg(chengji)) avg_chengji")
        .where(where)
        .field("(sum(chengji)) sum_chengji,(min(chengji)) min_chengji,(max(chengji)) max_chengji,(avg(chengji)) avg_chengji")
        .find();
    %>


    <div class="panel panel-default">
        <div class="panel-heading">
            <span class="module-name"> 学生成绩 </span>
            <span>列表</span>
        </div>
        <div class="panel-body">
            <div class="pa10 bg-warning">
                <form class="form-inline" id="formSearch" action="?">
                    <!-- form 标签开始 -->

                    <div class="form-group">
                        <i class="glyphicon glyphicon-search"></i>
                    </div>

                    <div class="form-group">
                        课程编号

                        <input type="text" class="form-control" style="" name="kechengbianhao" value="<%= request.getParameter("kechengbianhao") !=null ? request.getParameter("kechengbianhao") : "" %>" />
                    </div>
                    <div class="form-group">
                        课程名称

                        <input type="text" class="form-control" style="" name="kechengmingcheng" value="<%= request.getParameter("kechengmingcheng") !=null ? request.getParameter("kechengmingcheng") : "" %>" />
                    </div>
                    <div class="form-group">学生</div>
                    <div class="form-group">
                        学号

                        <input type="text" class="form-control" style="" name="xuehao" value="<%= request.getParameter("xuehao") !=null ? request.getParameter("xuehao") : "" %>" />
                    </div>
                    <div class="form-group">
                        学期

                        <select class="form-control select-update" data-value="<%= request.getParameter("xueqi") !=null ? request.getParameter("xueqi") : "" %>" id="xueqi" name="xueqi">
                            <option value="">请选择</option>
                            <% List<Map> select = new CommDAO().select("SELECT * FROM xueqixinxi ORDER BY id desc"); %>
 <% for (Map m : select) { %>

                            <option value="<%= m.get("id") %>"><%= m.get("xueqimingcheng") %></option>
                            <%} %>

                        </select>
                        <script>
                            $(".class_xueqi36 select-update").val($(".class_xueqi36 select-update").attr("data-value"));
                        </script>
                    </div>
                    <div class="form-group">
                        班级

                        <select class="form-control select-update" data-value="<%= request.getParameter("banji") !=null ? request.getParameter("banji") : "" %>" id="banji" name="banji">
                            <option value="">请选择</option>
                            <% select = new CommDAO().select("SELECT * FROM banjixinxi ORDER BY id desc"); %>
 <% for (Map m : select) { %>

                            <option value="<%= m.get("id") %>"><%= m.get("banjimingcheng") %></option>
                            <%} %>

                        </select>
                        <script>
                            $(".class_banji37 select-update").val($(".class_banji37 select-update").attr("data-value"));
                        </script>
                    </div>
                    <div class="form-group">
                        成绩

                        <input type="text" class="form-control" style="width: 80px" name="chengji_start" value="<%= request.getParameter("chengji_start") !=null ? request.getParameter("chengji_start") : "" %>" />-
                        <input type="text" class="form-control" style="width: 80px" name="chengji_end" value="<%= request.getParameter("chengji_end") !=null ? request.getParameter("chengji_end") : "" %>" />
                    </div>
                    <select class="form-control" name="order" id="orderby">
                        <option value="id">按发布时间</option>
                        <option value="xuefen">按学分</option>
                    </select>
                    <select class="form-control" name="sort" id="sort">
                        <option value="desc">倒序</option>
                        <option value="asc">升序</option>
                    </select>
                    <script>
                        $("#orderby").val("<%= orderby %>");
                        $("#sort").val("<%= sort %>");
                    </script>
                    <button type="submit" class="btn btn-default">搜索</button>

                    <button type="button" class="btn btn-default" onclick="exportXls()">导出</button>
                    <script>
                        function exportXls() {
                            var param = $("#formSearch").serialize();
                            var url = "xueshengchengji_export.jsp";
                            url += (url.indexOf("?") == -1 ? "?" : "&") + param;
                            location.href = url;
                        }
                    </script>

                    <!--form标签结束-->
                </form>
            </div>

            <div class="list-table">
                <table width="100%" border="1" class="table table-list table-bordered table-hover">
                    <thead>
                        <tr align="center">
                            <th width="60" data-field="item">序号</th>
                            <th>课程编号</th>
                            <th>课程名称</th>
                            <th>科目</th>
                            <th>学分</th>
                            <th>学号</th>
                            <th>姓名</th>
                            <th>学期</th>
                            <th>班级</th>
                            <th>成绩</th>
                            <th>评语</th>
                            <th>教师</th>
                            <th width="220" data-field="handler">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <%
                        int i = 0;
                        for (Map map : list) {
                            i++;
                        %>

                        <tr id="<%= map.get("id") %>" pid="">
                            <td width="30" align="center">
                                <label> <%= i %> </label>
                            </td>
                            <td><%= map.get("kechengbianhao") %></td>
                            <td><%= map.get("kechengmingcheng") %></td>
                            <td><% Map mapkemuxinxi40 = new CommDAO().find("SELECT kemumingcheng,id FROM kemuxinxi where id='" + map.get("kemu") + "'"); %>
<%= mapkemuxinxi40.get("kemumingcheng") %></td>
                            <td><%= map.get("xuefen") %></td>
                            <td><%= map.get("xuehao") %></td>
                            <td><%= map.get("xingming") %></td>
                            <td><% Map mapxueqixinxi41 = new CommDAO().find("SELECT xueqimingcheng,id FROM xueqixinxi where id='" + map.get("xueqi") + "'"); %>
<%= mapxueqixinxi41.get("xueqimingcheng") %></td>
                            <td><% Map mapbanjixinxi42 = new CommDAO().find("SELECT banjimingcheng,id FROM banjixinxi where id='" + map.get("banji") + "'"); %>
<%= mapbanjixinxi42.get("banjimingcheng") %></td>
                            <td><%= map.get("chengji") %></td>
                            <td><%= map.get("pingyu") %></td>
                            <td><%= map.get("jiaoshi") %></td>
                            <td align="center">
                                <a href="xueshengchengji_detail.jsp?id=<%= map.get("id") %>">详情</a>

                                <a href="xueshengchengji_updt.jsp?id=<%= map.get("id") %>">编辑</a>

                                <a href="xueshengchengji.jsp?a=delete&id=<%= map.get("id") %>" onclick="return confirm('确定要删除？')">删除</a>
                                <!--qiatnalijne-->
                            </td>
                        </tr>
                        <%} %>

                    </tbody>
                </table>
            </div>

            ${page.info}
            <p>成绩总和: <%= total.get("sum_chengji") %> 　　 成绩最小值: <%= total.get("min_chengji") %> 　　 成绩最大值: <%= total.get("max_chengji") %> 　　 成绩平均值: <%= total.get("avg_chengji") %> 　　</p>
        </div>
    </div>
</div>
<%@ include file="foot.jsp" %>

